package utils;


import cn.doitedu.jiaoyi.OrderInfo;
import cn.doitedu.product.*;
import cn.doitedu.yingxiao.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.lang.reflect.Field;
import java.util.HashMap;

public class TransferUtil {
    static HashMap<String, String> classMap = new HashMap<>();

    static {

        classMap.put("campain_info", CampainInfo.class.getName());
        classMap.put("couponfetchinfo", CouponFetchInfo.class.getName());
        classMap.put("couponinfo", CouponInfo.class.getName());
        classMap.put("groupon_info", GrouponInfo.class.getName());
        classMap.put("hongbao_info", HongBao.class.getName());
        classMap.put("merchant", Merchant.class.getName());
        classMap.put("miaoshainfo", MiaoShaInfo.class.getName());
        classMap.put("order_info", OrderInfo.class.getName());
        classMap.put("product", Product.class.getName());
        classMap.put("product_detail", ProductDetail.class.getName());
        classMap.put("product_type", ProductType.class.getName());
        classMap.put("shopinfo", ShopInfo.class.getName());
        classMap.put("userinfo", UserInfo.class.getName());
    }

    public static String transferData(String topic, JSONObject jsonObject) {
        String className = classMap.get(topic);
        String resultFinal = "";
        try {
            Class<?> aClass = Class.forName(className);
            Field[] fields = aClass.getDeclaredFields();


            for (Field field : fields) {
                String name = field.getName();
                String result = jsonObject.getString(name) == null ? "null" : jsonObject.getString(name);
                resultFinal += result + ",";
            }
        } catch (Exception e) {

        }

        String rt = resultFinal.substring(0, resultFinal.length() - 1);
        System.out.println(rt);
        return rt;
    }

    public static void main(String[] args) throws ClassNotFoundException {
        String className = "cn.doitedu.jiaoyi.OrderInfo";
        Class<?> aClass = Class.forName(className);
        Field[] fields = aClass.getDeclaredFields();

        for (Field field : fields) {
            String name = field.getName();
            System.out.println(name);
        }
    }
}
